using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace BlogKickStart.Models.Mapping
{
    public class BlogMap : EntityTypeConfiguration<Blog>
    {
        public BlogMap()
        {
            // Primary Key
            this.HasKey(t => t.BlogID);

            // Properties
            this.Property(t => t.Name)
                .HasMaxLength(256);

            // Table & Column Mappings
            this.ToTable("Blogs");
            this.Property(t => t.BlogID).HasColumnName("BlogID");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.Url).HasColumnName("Url");
            this.Property(t => t.StyleID).HasColumnName("StyleID");

            // Relationships
            this.HasOptional(t => t.Style)
                .WithMany(t => t.Blogs)
                .HasForeignKey(d => d.StyleID);

        }
    }
}
